﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using VectorPointDll;

namespace MINERP.BLL.AutoCutBoard
{
    public class Machine : IDisposable  
    {
         private bool _disposed;

         ClassVectorPointClass vec = new ClassVectorPointClass();
        // The stream passed to the constructor 
        // must be readable and not null.
        public Machine()
        {
            _disposed = false;
        }

        // Demonstrates using the resource.

        /// <summary>
        /// 将指定排版坐标文件输出，进行裁切。
        /// </summary>
        /// <param name="PointString">必选，字符串，指定排版文件对应的坐标信息</param>
        /// <param name="CoordinateString">字符串，字符串，输出指定排版文件的输出设备对应的校准结果</param>
        /// <param name="RotatePrint">必选，整数，指定裁切机的串口端口号</param>
        /// <returns>字符串，成功返回空，失败返回错误说明字符串</returns>
        public string VectorPointToMachine(string PointString, string CoordinateString, int COMPort, bool ConfirmDialog)
        {
            if (_disposed)
                throw new ObjectDisposedException("Resource was disposed.");
            string result = string.Empty;
            result = vec.VectorPointToMachine(PointString, CoordinateString, COMPort, ConfirmDialog);
            return result;
            
        }

        /// <summary>
        /// 判断机器是否忙
        /// </summary>
        /// <returns></returns>
        public bool isMachineBusy()
        {
            if (_disposed)
                throw new ObjectDisposedException("Resource was disposed.");
            return vec.isMachineBusy();
        }


        /// <summary>
        /// 显示相机实时画面窗口
        /// </summary>
        /// <param name="left">可选，整数，窗口位置横坐标</param>
        /// <param name="top">可选，整数，窗口位置纵坐标</param>
        /// <param name="Foreground">可选，布尔型，设定是否要显示在最上层</param>
        /// <returns>字符串，成功返回空，失败返回错误说明字符串</returns>

        public string ShowCameraWindow(int left, int top, bool Foreground)
        {
            if (_disposed)
                throw new ObjectDisposedException("Resource was disposed.");
            return vec.ShowCameraWindow(left, top, Foreground);
        }

        /// <summary>
        /// 隐藏相机实时画面窗口
        /// </summary>
        /// <returns>字符串，成功返回空，失败返回错误说明字符串</returns>
        public string HideCameraWindow()
        {
            if (_disposed)
                throw new ObjectDisposedException("Resource was disposed.");
            return vec.HideCameraWindow();
        }

        /// <summary>
        /// 显示裁切机和输出设备校准向导窗口。
        /// </summary>
        /// <param name="ComPort">必选，整数，指定裁切机的串口端口号</param>
        /// <param name="Calibration">可选，字符串，输入该设备上次的校准结果</param>
        /// <returns></returns>
        public string CalibrationWirzard(int ComPort,string Calibration )
        {
            if (_disposed)
                throw new ObjectDisposedException("Resource was disposed.");
            return vec.CalibrationWirzard(ComPort, Calibration);
        }

        /// <summary>
        /// 重新初始化设备，当设备长时间无响应时，或者要终止当前操作时，使用该方法。
        /// </summary>
        public void ResetMachine()
        {
            if (_disposed)
                throw new ObjectDisposedException("Resource was disposed.");
            vec.ResetMachine();
        }




        public void Dispose() 
        {
            Dispose(true);

            // Use SupressFinalize in case a subclass
            // of this type implements a finalizer.
            GC.SuppressFinalize(this);      
        }

        protected virtual void Dispose(bool disposing)
        {
        // If you need thread safety, use a lock around these 
        // operations, as well as in your methods that use the resource.
            if (!_disposed)
            {
                _disposed = true;   
            }
        }

    }
}
